<?php

namespace app\api\logic\book;

use think\facade\Request;
use app\common\repository\book\R as BookRRepository;

class BookSet
{
    public function __construct(
        BookRRepository $bookRRepository
    )
    {
        $this->bookRRepository = $bookRRepository;
    }
    public function getByUserId()
    {
        $userId = Request::param('id');
        $pageIndex = Request::param('index');
        $pageSize = Request::param('size');
        if (!$userId || !$pageIndex || !$pageSize) {
            return ['done' => false, 'code' => config('code.common.paramsRequire')];
        }
        $pageData = $this->bookRRepository->getBooksWithPage(['user_id' => $userId], [], ['index' => $pageIndex, 'size' => $pageSize]);
        return ['data' => $pageData['list'], 'page' => ['index' => $pageIndex, 'size' => $pageSize, 'count' => $pageData['count']]];
    }
}
